<template>
        <el-dialog  :title="title" :fullscreen="dialogFull" v-model="showSysMenuEdit" v-drag>
            <el-form ref="sysMenuEditFormRef" :rules="rules" :model="formObj" :label-position="labelPosition">
                <el-form-item prop="name"  label="菜单名称" :label-width="formLabelWidth">
                    <el-input v-model="formObj.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="上级菜单" :label-width="formLabelWidth">
                    <el-select v-model="parentName" placeholder="上级菜单" style="width: 100%" @change="_pNameChange">
                        <div v-for="item in pNameList">
                            <el-option  :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </div>
                    </el-select>
                </el-form-item>
                <el-form-item prop="code" label="菜单编码" :label-width="formLabelWidth">
                    <el-input v-model="formObj.code" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item prop="url"  label="菜单URL" :label-width="formLabelWidth">
                    <el-input v-model="formObj.url" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="菜单图标" :label-width="formLabelWidth">
                    <el-input v-model="formObj.pic" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="菜单排序" :label-width="formLabelWidth">
                    <el-input v-model="formObj.orderBy" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="备注" :label-width="formLabelWidth">
                    <el-input v-model="formObj.remark" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>

            <template #footer>
    <span class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </span>
            </template>
        </el-dialog>

</template>

<script>


    import {getReq, clearObject, postReq} from "../../../utils/api"
    import {ElMessage} from "element-plus";
    export default {
        name: "SysMenuEdit",
        components:{},
        mounted() {
            this.getPNameList()
        },
        data(){
            return{
                labelPosition:'right',
                formObj:{
                    name:undefined,
                    parentName:undefined,
                    code:undefined,
                    url:undefined,
                    pic:undefined,
                    remark:undefined,
                    orderBy:undefined,
                    pid:undefined
                },
                pNameList:[],
                parentName: undefined,
                showSysMenuEdit:false,
                title:'',
                dialogFull:false,
                formLabelWidth: '150px',
                rules: {
                    name: [
                        { required: true, message: '请输菜单名称', trigger: 'blur' }
                    ],
                    url: [
                        { required: true, message: '请输菜单URL', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输菜单编码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods:{
            open(){
                clearObject(this.formObj)
                this.showSysMenuEdit=true
            },
            _pNameChange(data){
                this.formObj.pid=data;
            },
            cancel(){
                this.showSysMenuEdit = false
            },
            save(){
                this.$refs['sysMenuEditFormRef'].validate((valid) => {
                    if (valid) {
                        postReq('/api/sys_resource/add',this.formObj).then(res=>{
                            if (res.data.data){
                                this.$emit('page')
                                this.showSysCompanyEdit=false
                                ElMessage.success({
                                    message: '添加成功！',
                                    type: 'success'
                                });
                            }
                        })
                        this.showSysMenuEdit = false
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            },
            getPNameList(){
               getReq('/api/sys_resource/list_parent',{}).then(res=>{
                   this.pNameList=res.data.data
               })
            },
        }
    }
</script>

<style scoped>

</style>